const execSync = require('child_process').execSync //同步子进程
let name = execSync('git show -s --format=%cn').toString().trim() //姓名
let message = execSync('git show -s --format=%s').toString().trim() //说明
let desc = `${name} ${message}`
const { version } = require('./package.json')

const path = require('path')
const ci = require('miniprogram-ci')
    ; (async () => {
        const project = new ci.Project({
            appid: 'wx98efbb36b9a16265',
            type: 'miniProgram',
            projectPath: path.resolve(__dirname, './dist/build/mp-weixin'), //项目路径,
            privateKeyPath: path.resolve(__dirname, './private.wx98efbb36b9a16265.key'),
            ignores: ['node_modules/**/*'],
        })
        const uploadResult = await ci.upload({
            project,
            version,
            desc,
            setting: {
                // es6: true,
                minifyJS: true,// 压缩 JS 代码
                minifyWXML: true,//     压缩 WXML 代码
                minifyWXSS: true,//压缩 WXSS 代码
                minify: true, //压缩所有代码，对应小程序开发者工具的 "压缩代码"
                // codeProtect:false    对应小程序开发者工具的 "代码保护"
                autoPrefixWXSS: true //对应小程序开发者工具的 "样式自动补全"
            },
            usingComponents: true,
            lazyCodeLoading: "requiredComponents",
            onProgressUpdate: console.log,
        }).then(res => {
            console.log('成功', res)
            // console.log(`版本${mainfest.versionName}`)
        }).catch(error => {
            console.log('失败', error)
            throw error
        })
        // console.log(uploadResult)
    })()

